<template>
	<view class="page-index">
		<!-- 标题栏 （有药丸，icon放左边） -->
		<view class="top" :style="{lineHeight:titleHeight+'px'}">
			<!-- 状态栏 -->
			<view :style="{height:statusBarHeight+'px'}"></view>
			<!-- 与药丸对齐 -->
			<view class="top-title" :style="{height:titleHeight+'px'}">
				<view class="notice-box">
					<image class="icon-notice" src="/static/notice.png" mode="aspectFit"></image>
					<view class="notice-num">77</view>
				</view>
				<text>早上好！张三先生</text>
			</view>
		</view>

		<!-- banner -->
		<view class="swiper">
			<swiper :indicator-dots="true" indicator-active-color="#88BF00" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="item in 5">
					<image class="swiper-item" src="/static/banner.png" mode="widthFix"></image>
				</swiper-item>
			</swiper>
		</view>

		<!-- 导航栏 -->
		<view class="nav">
			<block v-for="item in 5" :key="item">
				<view class="nav-item">
					<image class="nav-icon" src="/static/nav.png" mode="aspectFit"></image>
					<text class="nav-title">功能{{item+1}}</text>
				</view>
			</block>
		</view>

		<!-- 导航栏2 -->
		<view class="content">
			<block v-for="idx in contentBoxNum" :key="idx">
				<view class="content-item" @click="showPop(idx)">
					<image class="content-icon" :src="contentList[idx].icon" mode="aspectFit"></image>
					<text class="content-title">{{contentList[idx].title}}</text>
				</view>
			</block>
		</view>

		<!-- 弹窗 -->
		<pop-up ref="popUp" :info="contentItem"></pop-up>

		<!-- tabbar -->
		<view :style="{height:'180rpx'}"></view>
		<tab-bar></tab-bar>
	</view>
</template>

<script>
	import popUp from '@/components/index-popup/index.vue'
	export default {
		components: {
			popUp
		},
		data() {
			return {
				contentList: [{
					icon: '/static/img.png',
					title: '功能A'
				},
				{
					icon: '/static/img.png',
					title: '功能B'
				},
				{
					icon: '/static/img.png',
					title: '功能C'
				},
				{
					icon: '/static/img.png',
					title: '功能D'
				},
				{
					icon: '/static/img.png',
					title: '功能E'
				},
				{
					icon: '/static/img.png',
					title: '功能F'
				},
				{
					icon: '/static/img.png',
					title: '功能G'
				},
				{
					icon: '/static/img.png',
					title: '功能H'
				},
				{
					icon: '/static/img.png',
					title: '功能I'
				},
				{
					icon: '/static/img.png',
					title: '功能J'
				}],
				contentItem: {}
			}
		},
		computed: {
			contentBoxNum() {
				let left = this.contentList.length % 4
				return left == 0 ? this.contentList.length : 4 * (this.contentList.length % 4 + 1)
			}
		},
		onLoad() {

		},
		methods: {
			showPop(idx) {
				this.contentItem = this.contentList[idx]
				this.$refs.popUp.show()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F1F1F1;
	}
	
	.top {
		background-color: #272A3B;
		color: #88BF00;
		text-align: center;
		font-size: 30rpx;
		position: sticky;
		top: 0;
		width: 100vw;
		z-index: 9;

		.top-title {
			position: relative;

			.notice-box {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				left: 20rpx;
				top: 50%;
				transform: translateY(-50%);

				.icon-notice {
					width: 100%;
					height: 100%;
					position: absolute;
					left: 50%;
					top: 50%;
					transform: translate(-50%, -50%);
				}

				.notice-num {
					background-color: #FB000A;
					color: #FFFFFF;
					border-radius: 50%;
					text-align: center;
					width: 40rpx;
					height: 40rpx;
					line-height: 40rpx;
					position: absolute;
					top: 0;
					right: 0;
					transform: translate(50%, -50%);
				}
			}
		}
	}
	
	.swiper {
		.swiper-item {
			width: 100%;
			height: 100%;
		}
	}
	
	.nav {
		background-color: #272A3B;
		display: flex;
		justify-content: space-around;
		padding: 10rpx 0;
		
		.nav-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.nav-icon {
				width: 80rpx;
				height: 80rpx;
			}
			
			.nav-title {
				color: #FFFFFF;
				font-size: 26rpx;
			}
		}
	}
	
	.content {
		display: flex;
		flex-wrap: wrap;
		margin-top: 24rpx;
		background-color: #FFFFFF;
		
		.content-item {
			width: 25%;
			display: flex;
			flex-direction: column;
			align-items: center;
			border: 1px solid #EEEEEE;
			box-sizing: border-box;
			padding: 10rpx 0;
			
			.content-icon {
				width: 150rpx;
				height: 150rpx;
			}
			
			.content-title {
				color: #979797;
			}
		}
	}
</style>
